﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml;

namespace LicPdaService
{
   public class DelegatePrint
    {
        public static string Print(string xml)
        {
            string lsReturn = "";
            List<string> sqllists = new List<string>();
            string strSql = string.Empty;
            try
            {
             DataTable ldt = App.Xml2DataTable(xml);
                
            if (ldt.Rows.Count>0)
            {

                    App.DBconSet();
                App.Connection();
                strSql = "insert into Delegate_Print(type,value,ip,create_by,create_date) values(";
                strSql += "'" + ldt.Rows[0]["type"].ToString() + "','" + ldt.Rows[0]["values"].ToString() + "','" + ldt.Rows[0]["ip"].ToString() + "','" + ldt.Rows[0]["userid"] + "','"+System.DateTime.Now.ToString()+"')";
                sqllists.Add(strSql);
                    App.ExecuteSQLScriptLists(sqllists, App.DBconWMS);

                    XmlDocument doc = new XmlDocument();//返回报文
                XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
                doc.AppendChild(dec);
                XmlElement rootRet = doc.CreateElement("NewDataSet");
                XmlNode printNodes = doc.CreateElement("print_return");//返回用户节点
                XmlElement lxeuserid = doc.CreateElement("userid");
                XmlElement lxewhseid = doc.CreateElement("whseid");
                XmlElement lxetype = doc.CreateElement("type");
                XmlElement lxeip = doc.CreateElement("ip");
                XmlElement lxevalues = doc.CreateElement("values");
                XmlElement lxestatus = doc.CreateElement("status");

                lxeuserid.InnerText = ldt.Rows[0]["userid"].ToString();
                lxewhseid.InnerText = ldt.Rows[0]["whseid"].ToString();
                lxetype.InnerText = ldt.Rows[0]["type"].ToString();
                lxeip.InnerText = ldt.Rows[0]["ip"].ToString();
                lxevalues.InnerText = ldt.Rows[0]["values"].ToString();
                lxestatus.InnerText = "打印成功！";
                printNodes.AppendChild(lxeuserid);
                printNodes.AppendChild(lxewhseid);
                printNodes.AppendChild(lxetype);
                printNodes.AppendChild(lxeip);
                printNodes.AppendChild(lxevalues);
                printNodes.AppendChild(lxestatus);
                rootRet.AppendChild(printNodes);
                doc.AppendChild(rootRet);
                lsReturn = doc.InnerXml;

                //FastReport.Report report = new FastReport.Report(); ;
                //if (ldt.Rows[0]["type"].ToString()=="ORDER")
                //{
                //    DataTable ldt_head = App.ws.GetTable("select * from Receipt where receiptkey='" + ldt.Rows[0]["values"].ToString() + "'", "Receipt", false, "");
                //    DataTable ldt_detail = App.ws.GetTable("select * from ReceiptDetail where receiptkey='" + ldt.Rows[0]["values"].ToString() + "'", "ReceiptDetail", false, "");
                //// ds.Tables.Add(ldt);
                // //ds.Tables.Add(ldt_detail);

                // report.RegisterData(ldt_head, "dt");
                // report.RegisterData(ldt_detail, "detail");
                // report.Print();
                //}
            }
            }
            catch (Exception ex)
            {
                App.Log("pring", ex.Message.ToString());
                throw;
            }
            return lsReturn;
        }
    }
}
